<?php
/* 
 * 意见反馈（留言） 
 * 
 * */
namespace Admin\Controller;
class FeedBackController extends ComController{
	/*  
	 * 显示意见反馈
	 * */
	public function index(){
		
		$user_id = $this->userType();
		
		//根据用户的id号，去fend_back 表中查询反馈内容
		$feed = M('feed_back');

		$phone =trim($_GET['phone']);  
		$status = (int)$_GET['statu'];
		
		$where="sc_id = $user_id";
		if(!empty($phone)){
			$where.=" and phone=$phone";
		}
		if(!empty($status)){
			$where.=" and status=$status";
		}
		// 分页 		
		$p= intval($_GET['p'])?$_GET['p']:1;
		$pagesize = 15;#每页数量
        $offset = $pagesize * ($p - 1);//计算记录偏移量
		$count = $feed->where($where)->count();
		$page = new \Think\Page($count, $pagesize);
		$page = $page->show();
		$this->assign('page',$page);
		
		$feed_info = $feed
					->where($where)
					->limit($offset . ',' . $pagesize)
					->order('add_time desc')
					->select();
		
		
		$this->assign('feed_info',$feed_info);
		$this->display();

	}
	//标记为已回复
	public function enable(){
		$id = (int)$_GET['id'];
		if(!empty($id)){
			$feed = M('feed_back');
			$res = $feed->save(array('id'=>$id,'status'=>2,'update_time'=>time()));
			if($res ==1){
				$this->success('修改成功',$_SERVER['HTTP_REFERER']);
			}else{
				$this->error('修改失败',$_SERVER['HTTP_REFERER']);
			}
		}else{
			$this->error('参数错误，请重新选择');
		}
	}
	
	
	/* 判断当前用的登录的类别 */
	public function userType(){
		//获取幼儿园id
		$uid=$_SESSION['uid'];
		if(empty($uid)){
			$this->error('您尚未登录，请登录',U('Login/login'));
		}
		//查询member表的pid  pid
		$member = M('member');
		$type_info = $member->field('uid,name,pid,level')->where("uid = $uid")->find();
		if(!empty($type_info)){
			if($type_info['level'] ==2){
				//教师登录
				$sc_id = $type_info['pid'];

			}elseif($type_info['level'] ==1){
					
				//幼儿园管理员登录
				$sc_id = $type_info['uid'];
	
			}elseif ($type_info['level'] ==0){
				//平台管理员登录
				$sc_id = $type_info['uid'];
			}else{
				//未获得等级
				$this->error('未获得等级信息',U('Index/index'));
			}
			return  $sc_id;
		}else{
			$this->error('未查询到登录信息，请重新登录',U('Login/logout'));
		}
			
	
	}
	
}

